package com.longtop.db;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;
import com.longtop.dbHelper.DbHelper;
import com.longtop.model.Tables;



public class OperatorXML {

	private static final String FILE_NAME = "E:\\workspace\\longtopDBTool\\src\\tableConfig.xml";
	private Marshaller marshaller;
	private Unmarshaller unmarshaller;
	public Marshaller getMarshaller() {
		return marshaller;
	}
	public void setMarshaller(Marshaller marshaller) {
		this.marshaller = marshaller;
	}
	public Unmarshaller getUnmarshaller() {
		return unmarshaller;
	}
	public void setUnmarshaller(Unmarshaller unmarshaller) {
		this.unmarshaller = unmarshaller;
	}
	public static String getFileName() {
		return FILE_NAME;
	}
	
	/**
	 * д�����
	 * @param obj
	 * @throws IOException
	 */
	public void saveObject(Object obj,String file_name) throws IOException {
		FileOutputStream os = null;
		try{
			os = new FileOutputStream(file_name);
			this.marshaller.marshal(obj, new StreamResult(os));
		}finally{
			if(os!=null){
				os.close();
			}
		}
	}
	
	public Object loadObject(String file_name)throws IOException{
		FileInputStream is = null;
		Object obj = null;
		try{
			is = new FileInputStream(file_name);
			obj = this.unmarshaller.unmarshal(new StreamSource(is));
		}finally{
			if(is!=null){
				is.close();
			}
		}
		return obj;
	}
	

}
